﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="MessageBoard.aspx.cs" Inherits="LizzabethBrownRealEstate.Views.Home.MessageBoard" %>
<%@ Import Namespace="LizzabethBrownRealEstate.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <script type="text/javascript">
    function setCategory(sel){
        var category = sel.options[sel.selectedIndex].value;
        window.location = "/Users.ashx/MessageBoard?categoryId=" + category;
    }
</script>
<% LBRDataContext dc = new LBRDataContext(); %>
<div class="MessageBoardContent">
    <%  object script = new { onchange = "setCategory(this)" }; 
        Category selectedCategoy = dc.GetCategory(1); 
        selectedCategoy = dc.GetCategory(int.Parse(ViewData["CategoryId"].ToString()));
        if (selectedCategoy == null) selectedCategoy = dc.GetCategory(1);
    %>
    
    <div class="CategoryDiv">
        <label>Category:</label> <%= Html.DropDownList(null, "CategoryList", new SelectList( dc.Categories, "CategoryId", "Name", selectedCategoy.CategoryId.ToString()), script)%>
        <%=Html.ActionLink("New Topic", "NewTopic", "Users", ViewData["CategoryId"], null) %>
    </div>
    <div class="MessageBoardSeparator">&nbsp;</div>
    
    <table class="MessageBoard">
    <% foreach (Topic t in dc.GetTopicsByCategory(int.Parse(ViewData["CategoryId"].ToString()))) { %>
    <% object topicId = new {topicId = t.TopicId}; %>
    <% User u = dc.GetUser(t.UserId.ToString());%>
    <tr class="MessageRow">
        <% if (u.Deleted)
           { %>
            <td class="TopicLink" title="This user's profile has been deleted"><%= Html.ActionLink(t.Title, "ViewTopic", topicId) %></td>
        <%}
           else
           { %>
            <td class="TopicLink"><%= Html.ActionLink(t.Title, "ViewTopic", topicId) %></td>
           <%} %>
        <td class="MessageDate"><%=t.CreateDate %></td>
        <td class="MessageUser"><%= u.UserName%></td>        
    </tr>
    <%} %>
    </table>
</div>
</asp:Content>
